package main

import (
	"context"
	"flag"
	"fmt"
	"log"

	"rpctest/service"

	"github.com/smallnest/rpcx/client"
)

var (
	addr = flag.String("addr", "localhost:8972", "server address")
)

func main() {
	flag.Parse()
	// 直接连接rpc服务器，连接会话
	d, err := client.NewPeer2PeerDiscovery("tcp@"+*addr, "")
	if err != nil {
		log.Fatalf("failed to call: %v", err)
	}
	// 获取客户端接口
	xclient := client.NewXClient("xiaoxu", client.Failtry, client.RandomSelect, d, client.DefaultOption)
	defer xclient.Close()
	//接口方法参数
	args := &service.Param{A: 10, B: 8, C: "+"}
	var reply service.Result
	//客户端接口调用方法
	err = xclient.Call(context.Background(), "Compute", args, &reply)
	if err != nil {
		log.Fatalf("failed to call: %v", err)
	}
	fmt.Printf("调用rpc的结果为:%d", reply.D)

	// hello函数
	var replay1 service.ResultStr
	xclient.Call(context.Background(), "Hello", args, &replay1)
	fmt.Println(replay1.Str)
}
